/**
  CNOK project, IMP-CAS

  \class TAFileIO
  \brief file operations, e.g., copying files. This is a static tool class.
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2023/02/04
  \date Last modified: 2023/02/04 by SUN Yazhou
  \copyright 2020-2023 SUN Yazhou
  \copyright CNOK project, IMP-CAS
*/

#include <fstream>
#include "TAFileIO.h"
#include "TAException.h"

TAFileIO::TAFileIO(){}

TAFileIO::~TAFileIO(){}

void TAFileIO::Copy(const string &src, const string &dst){
  const char *s = src.c_str(), *d = dst.c_str();
  std::ifstream in(s, std::ios::binary);
  std::ofstream out(d, std::ios::binary);
  if(in.fail()) TAException::Error("TAFileIO", "Copy: %s open error", s);
  if(out.fail()) TAException::Error("TAFileIO", "Copy: fail to create %s", d);
  out << in.rdbuf();
  out.close();
  in.close();
} // end of member function Copy
